# --**coding:utf-8**--
# Create by author: hemq

'''
    封装db操作，获取所有db数据
'''
from channel.models import ChannelListConfig, Nodeconfig, ChannelConfigList


def get_channel_list():
    channel_list = ChannelListConfig.objects.all()
    ret = {}
    title, ch_list = [], []
    print '2222', channel_list
    # if channel_list is not None:
    #     for item in channel_list:
    #         if item['name']:
    #             title.append(item['name'])
    #             ch_list.append(item)
    ret['title'] = title
    ret['list'] = ch_list
    print 'ret:', ret
    return ret

def get_channel_list1():
    channel_list = ChannelConfigList.objects.all().exists()
    ret = {}
    print 'zazaza'
    title, ch_list = [], []
    print '2222', channel_list
    # if channel_list is not None:
    #     for item in channel_list:
    #         if item['name']:
    #             title.append(item['name'])
    #             ch_list.append(item)
    ret['title'] = title
    ret['list'] = ch_list
    print 'ret:', ret
    return ret


def get_360_info_channelNum():
    '''
    :return: 360加固包相关渠道号信息
    '''
    channel_360_num = []
    channel_360_info = ChannelListConfig.objects.filter(projectshortname='jdb', jiagu='360')
    for info in channel_360_info:
        channel_360_num.append(info.code)
    return channel_360_num


def get_360_info_channelName():
    '''
    :return: 360加固包相关应用市场信息
    '''
    channel_360_name = []
    channel_360_info = ChannelListConfig.objects.filter(projectshortname='jdb', jiagu='360')
    for info in channel_360_info:
        channel_360_name.append(info.name)
    return channel_360_name


def get_bd_info():
    '''
    :return: 百度加固包相关渠道号信息
    '''
    channel_baidu_num = []
    channel_baidu_info = ChannelListConfig.objects.filter(projectshortname='jdb', jiagu='bd')
    for info in channel_baidu_info:
        channel_baidu_num.append(info.code)
    return channel_baidu_num


def get_bd_channelName():
    '''
    :return: 百度加固包相关应用市场信息
    '''
    channel_baidu_name = []
    channel_baidu_info = ChannelListConfig.objects.filter(projectshortname='jdb', jiagu='bd')
    for info in channel_baidu_info:
        channel_baidu_name.append(info.name)
    return channel_baidu_name


def get_keyAlias(projectshortname, platform):
    '''
    :return: 根据传参判断app类型，返回对应app的keyAlias
    '''
    apk_keyAlias = ''
    for keyAlias in Nodeconfig.objects.filter(projectshortname=projectshortname, platform=platform):
        apk_keyAlias = keyAlias.keyalias
    return apk_keyAlias


def get_keyPassword(projectshortname, platform):
    '''
    :return: 根据传参判断app类型，返回对应app的keyPassword
    '''
    apk_keyPassword = ''
    for keyPassword in Nodeconfig.objects.filter(projectshortname=projectshortname, platform=platform):
        apk_keyPassword = keyPassword.keypassword
    return apk_keyPassword


if __name__ == '__main__':
    get_channel_list()